/*
 * @Date: 2025-07-16 15:49:28
 * @Auth: 463997479@qq.com
 * @LastEditors: 463997479@qq.com
 * @LastEditTime: 2025-08-04 10:47:36
 * @FilePath: \corpus\src\pages\AuthKnowledge\hook\index.ts
 */
import { useLocation } from '@umijs/max';
import { useRequest } from 'ahooks';
import { Form, message } from 'antd';
import { useEffect, useState } from 'react';
import { createContainer } from 'unstated-next';
import { applyReview } from '@/services/ant-design-pro/apply';
export default createContainer(() => {
  const [visible, setVisible] = useState(false);
  const [form] = Form.useForm();
  const location = useLocation() as Record<any, any>;
  const knowledgeData = location?.state?.data ? location?.state?.data : '';
  /**
   * 审核
   */
  const applyReviewData = useRequest(
    async (arg) => {
      const res = await applyReview(arg);
      if (res) {
        message.success('审核成功！', 0.5);
        setVisible(false);
        history.back();
      } else {
        message.error(`审核失败，错误信息!`, 0.5);
      }
      form.resetFields();
    },
    { manual: true },
  );
  useEffect(() => {
    if (visible && knowledgeData) {
      form.setFieldValue('id', knowledgeData.id);
    }
  }, [knowledgeData, visible]);
  return {
    visible,
    setVisible,
    form,
    knowledgeData,
    applyReviewData,
  };
});
